package com.xiaoyu.client.adapter.discovery;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xiaoyu.client.R;
import com.xiaoyu.client.model.discovery.RankParam;
import com.xiaoyu.client.model.discovery.RankingBean;
import com.xiaoyu.commonlib.utils.CCircleImageView;

import java.util.ArrayList;
import java.util.List;

/**
 * 前十排名列表适配器
 */
public class RankingAdapter extends BaseAdapter {
    private Context mContext;
    private List<RankParam> mList = new ArrayList<>();

    public RankingAdapter(Context mContext, List<RankParam> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public RankParam getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    class ViewHolder{
        TextView rankNumTxt;//排行第几名
        CCircleImageView photoImg;
        TextView nameTxt;
        TextView helpedTxt;//帮助数量
        TextView adoptedTxt;//被采纳数量
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_ranking_top_ten,parent,false);
            holder = new ViewHolder();
            holder.rankNumTxt = convertView.findViewById(R.id.item_ranking_top_ten_rank_num);
            holder.photoImg = convertView.findViewById(R.id.item_ranking_top_ten_portrait_img);
            holder.nameTxt = convertView.findViewById(R.id.item_ranking_top_ten_name_txt);
            holder.helpedTxt = convertView.findViewById(R.id.item_ranking_top_ten_helped_num_txt);
            holder.adoptedTxt = convertView.findViewById(R.id.item_ranking_top_ten_Adopted_num_txt);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (position == 0){
            holder.rankNumTxt.setTextColor(Color.parseColor("#ffd83c"));
        }else if (position == 1){
            holder.rankNumTxt.setTextColor(Color.parseColor("#84acfe"));
        }else if (position == 2){
            holder.rankNumTxt.setTextColor(Color.parseColor("#60de96"));
        }else if (position == 3){
            holder.rankNumTxt.setTextColor(Color.parseColor("#999999"));
        }
        holder.rankNumTxt.setText(""+(position+1));
        Glide.with(mContext).load(mList.get(position).getUserPhoto()).into(holder.photoImg);
        holder.nameTxt.setText(mList.get(position).getNickname());
        holder.helpedTxt.setText("帮助 "+mList.get(position).getRankingCount());
        holder.adoptedTxt.setText("采纳 "+mList.get(position).getThinkCount());
        return convertView;
    }
}
